{inc:header.htm}
<div class="m">
    <div class="head">
        <dl>
            <input id="add" type="button" value="新用户" class="but1" />
            <dt style="display:inline;float:right">
                <form class="search" method="post" action="index.php?u=user-index">
                    <input type="submit" value="搜索用户" class="but1" style="float:right;margin:0 8px 0 5px">
                    <input type="search" name="keyword" value="{$keyword}" style="float:right;width:150px;padding:1px">
                </form>
            </dt>
        </dl>
    </div>

    <div class="p c2">
        <div class="cc">
            {if:empty($user_arr)}
            <div class="sky warning bnote"><i></i><b>暂无内容</b></div>
            {else}
            <table class="tb2">
                <tr class="tit">
                    <th class="th" width="25"><input type="checkbox" id="check_all"></th>
                    <th class="th">序号</th>
                    <th class="th">用户名</th>
                    <th class="th">Email</th>
                    <th class="th">注册时间</th>
                    <th class="th" width="150">操作</th>
                </tr>

                {loop:$user_arr $v}
                <tr class="li">
                    <td class="col"><input type="checkbox" name="chk_row" _id="{$v[uid]}"></td>
                    <td class="col">{$v[uid]}</td>
                    <td class="col">{$v[username]}</td>
                    <td class="col">{$v[email]}</td>
                    <td class="col">{php} echo date('Y-m-d H:i:s', $v['regdate']);{/php}</td>
                    <td class="col">
                        <a class="but3" href="javascript:edit({$v[uid]});">编辑</a>
                        <a class="but3 del" href="javascript:del({$v[uid]});">删除</a>
                    </td>
                </tr>
                {/loop}
            </table>

            <div class="page cf"><span>共 <font color="red">{$total}</font> 篇</span>{$pages}</div>
            {/if}
        </div>
    </div>
</div>
<script type="text/javascript">
    $("#add").click(function(){
        parent.oneTab("user-add");
    });

    //全选
    $("#check_all").click(function(){
        var bool = $(this)[0].checked;
        var len = $("input[name='chk_row']").length;
        for(var i=0; i<len; i++) {
            $("input[name='chk_row']").eq(i)[0].checked = bool;
        }
        bool ? buttonDis() : $("#batch_del").remove();
    });

    //是否显示删除按钮
    $("input[name='chk_row']").click(function(){
        var len = $("input[name='chk_row']:checked").length;
        len ? buttonDis() : $("#batch_del").remove();
    });

    //显示删除按钮
    function buttonDis() {
        if(!$("#batch_del").length) $(".head>dl").append('<input id="batch_del" onclick="batch_del()" type="button" value="批量删除" class="but1" />');
    }

    //编辑
    function edit(uid) {
        parent.oneTab("user-edit-uid-"+uid);
    }

    //删除
    function del(uid) {
        twAjax.confirm("删除不可恢复，确定删除？", function(){
            twAjax.postd("index.php?u=user-del-ajax-1", {"uid":uid}, function(data){
                twAjax.alert(data);
                if(window.twData.err==0) setTimeout(function(){ window.location.reload(); }, 1000);
            });
        });
    }

    //批量删除
    function batch_del() {
        twAjax.confirm("删除不可恢复，确定删除？", function(){
            var id_arr = {};
            var len = $("input[name='chk_row']").length;
            for(var i=0; i<len; i++) {
                var obj = $("input[name='chk_row']").eq(i);
                if(obj[0].checked) {
                    id_arr[i] = [obj.attr("_id")];
                }
            }
            twAjax.postd("index.php?u=user-batch_del-ajax-1", {"id_arr":id_arr}, function(data){
                twAjax.alert(data);
                if(window.twData.err==0) setTimeout(function(){ window.location.reload(); }, 1000);
            });
        });
    }
</script>
</body>
</html>
